﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AuthorTests.aspx.cs" Inherits="JustTest.Author.AuthorTests" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">    
        <asp:ValidationSummary runat="server" ShowSummary="true" DisplayMode="BulletList" Style="color: Red" />
        <asp:FormView runat="server"
             ID="TestCreateFormView"
             InsertMethod="TestCreateFormView_InsertItem1"
             ItemType="JustTest.Models.Test"
             DefaultMode="Insert">
            <InsertItemTemplate>
                <table>
                    <tr>
                        <td>Category</td>
                        <td><asp:DropDownList runat="server"
                             ID="CategoryDropDown"
                             SelectMethod="CategoryDropDown_SelectItem"
                             ItemType="JustTest.Models.Category"
                             DataTextField="Name"
                             DataValueField="Id"
                             SelectedValue="<%# BindItem.Category.Id %>">
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td>Title</td>
                        <td><asp:TextBox ID="TitleInput" runat="server" Text="<%#BindItem.Title %>" /></td>
                        <asp:RequiredFieldValidator Display="None" runat="server" ErrorMessage="Title Is Required !" ControlToValidate="TitleInput" >
                        </asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ControlToValidate="TitleInput"  Display="None"
                                ValidationExpression="[A-Za-z0-9?.!-,:; ]{6,}" ErrorMessage="Title Has To Be With Min Length 6 !" runat="server">
                        </asp:RegularExpressionValidator>
                    </tr>
                    <tr>
                        <td colspan="2"><asp:Button runat="server" CssClass="btn btn-inverse" CommandName="Insert" Text="Create Test" /></td>
                    </tr>
                </table>
            </InsertItemTemplate>
        </asp:FormView>
        <hr />
      <asp:GridView runat="server"
           CssClass="table table-hover table-stripped"
           ID="TestsGridView"
           AutoGenerateColumns="false"
           SelectMethod="TestsGridView_GetData"
           ItemType="JustTest.Models.Test"
           AllowSorting="true"
           OnRowCommand="TestsGridView_RowCommand"
           DataKeyNames="Id"
           Caption="My Tests">
          <Columns>
              <asp:DynamicField HeaderText="Title" DataField="Title" SortExpression="Title" />
              <asp:TemplateField HeaderText="Questions">
                  <ItemTemplate>
                      <%# Item.Questions.Count %>
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText="Category">
                  <ItemTemplate>
                      <%# Item.Category.Name%>
                  </ItemTemplate>
              </asp:TemplateField>
              <asp:DynamicField HeaderText="Status" DataField="Status" SortExpression="Status" />
              <asp:TemplateField HeaderText="Action">
                  <ItemTemplate>
                       <asp:Button Enabled="<%# Item.Status == JustTest.Models.TestStatus.Unpublished %>"
                            runat="server" CommandName="CustomEdit" CommandArgument="<%#: Item.Id %>" Text="Edit"  CausesValidation="false" CssClass="btn btn-info"></asp:Button>
                  </ItemTemplate>
              </asp:TemplateField>
          </Columns>
      </asp:GridView>
</asp:Content>